package com.example.ui.learn.util;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.huashangapp.R;
import com.example.huashangapp.R.color;


import com.example.util.AsyncLoadImage;

public class MyListViewAdapter4 extends BaseAdapter {
	private LayoutInflater inflater;
	private ArrayList<Listen> list;
	public static int currentPosition = -1;
	
	public MyListViewAdapter4(Context mContext,
			ArrayList<Listen> list) {
		inflater = LayoutInflater.from(mContext);
		this.list = list;
	}

	public ArrayList<Listen> getCcInfos() {
		return list;
	}

	public void setCcInfos(ArrayList<Listen> list) {
		this.list = list;
		if (list == null) {
			this.list = new ArrayList<Listen>();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		Listen l=list.get(position);
		
		
		
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.la_item, null);
			holder = new Holder();
              holder.title=(TextView) convertView.findViewById(R.id.li_txt);
			 holder.listen=(ImageView) convertView.findViewById(R.id.li_ivlisten);
			convertView.setTag(holder);
			
		} else {
			
			holder = (Holder) convertView.getTag();
		}
		holder.title.setText(l.getTitle());
		if(l.getListen().equals("true")){
			holder.listen.setVisibility(View.VISIBLE);
		}else{
			holder.listen.setVisibility(View.GONE);
		}
			
        if ( position == currentPosition) {
			holder.title.setTextColor(inflater.getContext().getResources().getColor(R.color.blue));
		}else{
			holder.title.setTextColor(inflater.getContext().getResources().getColor(R.color.white));
		} 

		return convertView;
	}

	 class Holder {
		TextView title;
		ImageView listen;
	}
   
	
	
}
